package cc.mllt.demoaopmybatisauth.demos.web.config;

import cc.mllt.demoaopmybatisauth.demos.web.interceptor.DataScopeInnerInterceptor;
import cc.mllt.demoaopmybatisauth.demos.web.service.CacheDataService;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisPlusConfig {
    @Autowired
    CacheDataService cacheDataService;

    // MyBatis-Plus 的拦截器（处理分页等）
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 【注意】如果其他地方配置了分页插件，请注释掉这一行，不然会出现问题，例如 limit重复
        // 添加数据范围拦截器
        interceptor.addInnerInterceptor(new DataScopeInnerInterceptor(cacheDataService));
        return interceptor;
    }
}